/**
 * Created by Yang on 2014/9/4.
 */

var Handler = require('../Handler');
var Order = require('../../model').Order;
var util = require('util');
var handler = function(req,res){
    Handler.call(this);
    this.req = req;
    this.res = res;
}

util.inherits(handler,Handler);



handler.prototype.handle = function(){
    var scope = this;
    var tradeNo = this.req.query.out_trade_no;
    Order.findOne({tradeNo:tradeNo},function(err,order){
        if(order){
            order.havePay = true;
            order.save(function(err,result){
                if(!err){
                    scope.simpleResponse(null,{ok:1});
                }else{
                    scope.simpleResponse({err:1});
                }
            });
        }else{
            scope.simpleResponse({err:1});
        }
    })
}

module.exports = handler;